package com.tengits.upgrade;

import android.content.Context;
import android.os.Environment;

import java.io.File;
import android.os.Build;
import android.util.Log;


public class PathUtils {

    public static String getRootFolder(Context context) {
        // 获取sdCard的路径
        File extStore = Environment.getExternalStorageDirectory();
        // 获取绝对路径
        String path = extStore.getAbsolutePath() + File.separator + "TenRoad" + File.separator;
        final File file = new File(path);
        if (!file.exists())
            file.mkdir();
        return path;
    }

    // 版本下载的文件路径
    public static String appDownLoadPath(Context context) {
        File file = null;
        String path = "";
        if (Build.VERSION.SDK_INT >= 30) {
            //android 11
            path = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + File.separator;
            Log.e("upgrade", path);
            file = new File(path);
        } else {
            path = getRootFolder(context) + "document" + File.separator;
            file = new File(path);
        }

        if (!file.exists())
            file.mkdir();
        return path;
    }
}
